export class GlobalService {
  static HOST = "https://cardarena.site/api";
  // static HOST = "http://localhost:3000";
  static STATIC_FILE_HOST = "https://cardarena.site";
  static STATIC_ASSETS_HOST = "https://cardarena.site/assets";
  static FILE_HOST = "https://cdn2.cardarena.site/assets";
  static CDN_HOST = "https://cdn2.cardarena.site/";

  static ID_COUNT_MAP: { [key: number]: number } = {};
  static DECKNO_COUNT_MAP: { [key: string]: number } = {};
  static DEFAULT_SEARCH_REQ: { [key: string]: any } = {};
  static DEFAULT_CONAN_SEARCH_REQ: { [key: string]: any } = {};

  static DISPLAY: { [key: string]: boolean } = {};

  static EFFECT_CACHE: { [key: string]: any } = {}

  static clearCurrentEditingDeckInfo() {
    GlobalService.ID_COUNT_MAP = {};
    GlobalService.DECKNO_COUNT_MAP = {};
    GlobalService.DEFAULT_SEARCH_REQ = {};
  }

  static uploadImage(filePath: string) {
    return new Promise<string>(
      (resolve, reject) => {
        wx.uploadFile({
          url: `${GlobalService.HOST}/uploadImage`,
          filePath,
          name: 'file',
          success: (response) => resolve(response.data as string),
          fail: (err) => reject(err)
        })
      });
  }

  static getGoofishItemId(url: string) {
    return new Promise<string>(
      (resolve, reject) => {
        wx.request({
          url: `${GlobalService.HOST}/getGoofishItemId`,
          method: "POST",
          data: { url },
          success: (response) => resolve(response.data as string),
          fail: (err) => reject(err)
        });
      }
    )
  }
  static getAppConf() {
    return new Promise<{
      uaUserGroupQR: string
    }>(
      (resolve, reject) => {
        wx.request({
          url: `${GlobalService.HOST}/appConf`,
          method: "GET",
          success: (response) => resolve(response.data as {
            uaUserGroupQR: string
          }),
          fail: (err) => reject(err)
        });
      }
    )
  }


}